{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/word-subsets\n",
    "\n",
    "\n",
    "Time Limit Exceeded\n",
    "\n",
    "\n",
    "```python\n",
    "import functools\n",
    "\n",
    "class Solution:\n",
    "    @functools.lru_cache(maxsize=None)\n",
    "    def char_count(self, text:str) -> Dict[str,int]:\n",
    "        b_dict = {}\n",
    "        for c in text:\n",
    "            if c in b_dict.keys():\n",
    "                b_dict[c] += 1\n",
    "            else:\n",
    "                b_dict[c] = 1\n",
    "        return b_dict\n",
    "        \n",
    "    def is_subset(self, a_dict:Dict[str,int], b:str) -> bool:\n",
    "        b_dict = self.char_count(b)\n",
    "        for c in b_dict.keys():\n",
    "            if c not in a_dict.keys():\n",
    "                return False\n",
    "            else:\n",
    "                if not a_dict[c] >= b_dict[c]:\n",
    "                    return False\n",
    "        return True\n",
    "    \n",
    "    def wordSubsets(self, A: List[str], B: List[str]) -> List[str]:\n",
    "        results:List[str] = []\n",
    "            \n",
    "        for a in A:\n",
    "            ok = True\n",
    "            a_dict = self.char_count(a)\n",
    "            for b in B:\n",
    "                if not self.is_subset(a_dict, b):\n",
    "                    ok = False\n",
    "                    break\n",
    "            if (ok):\n",
    "                results.append(a)\n",
    "            \n",
    "        return results\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
